package cn.appsys.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;

import cn.appsys.pojo.AppCategory;
import cn.appsys.pojo.AppInfo;
import cn.appsys.pojo.DataDictionary;
import cn.appsys.service.appCategory.AppCategoryService;
import cn.appsys.service.appInfo.AppInfoService;
import cn.appsys.service.dataDictionary.DataDictionaryService;
import cn.appsys.service.devUser.DevUserService;

@Controller
public class AppInfoController {
	
	ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
	DevUserService devUserService=(DevUserService) context.getBean("devUserService");
	DataDictionaryService dataDictionaruService=(DataDictionaryService) context.getBean("dataDictionaryService");
	AppCategoryService appCategoruService=(AppCategoryService) context.getBean("appCategoryService");
	AppInfoService appinfoService=(AppInfoService) context.getBean("appInfoService");
	
	@RequestMapping(value="/dev/appinfoadd")
	public String appinfoadd(){
		return "developer/appinfoadd";
	}
	//获得平台列表
	@RequestMapping(value="/dev/datadictionarylist.json",method=RequestMethod.GET)
	@ResponseBody
	public Object datadictionarylist(@RequestParam(value="tcode",required=false)String tcode ){
		List<DataDictionary> datadictionarylist=dataDictionaruService.getStatusList(tcode);
		return JSON.toJSONString(datadictionarylist);
	}
	//获得级别菜单
	@RequestMapping(value="/dev/categorylevellist.json",method=RequestMethod.GET)
	@ResponseBody
	public Object applevelist(@RequestParam(value="pid",required=false) String pid){
		Integer _pid=null;
		if(null != pid && "" != pid){
			_pid=Integer.parseInt(pid);
		}
		List<AppCategory> categoryLeve1List=appCategoruService.getCategoryleve(_pid);
		return  JSON.toJSONString(categoryLeve1List);
	}
	
	//验证APK名称是否存在
	@RequestMapping(value="/dev/apkexist.json")
	@ResponseBody
	public Object apkExist(@RequestParam(value="APKName",required=false)String APKName){
		AppInfo appInfo=appinfoService.getAppInfo(APKName);
		Map<String, String> apkName=new HashMap<String,String>();
		if(null == appInfo){
			apkName.put("APKName", "exist");
		}else{
			apkName.put("APKName", "noexist");
		}
		return JSON.toJSONString(apkName);
	}
	
	@RequestMapping(value="appinfoaddsave")
	public String appInfoAddSave(AppInfo addinfo){
		int result=appinfoService.add(addinfo);
		
		return null;
		
	}

}
